package day12;

import java.util.Scanner;

public class Demo6 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入年龄");
        String sex=sc.next();
        if("男".equals(sex) || "女".equals(sex)){
            System.out.println("ok");
        }
        else {
            try {
                throw new SexException("性别只能输入男或女");
            }
            catch (SexException e){
                System.err.println("ok");
            }
        }
    }
}

class SexException extends RuntimeException{
    public SexException(String msg){
        //必须要父类构造  否则msg无法正常赋值
        super(msg);
    }
}